package com.ldc.wandroid.adapter;

import android.text.TextUtils;
import android.view.View;
import android.widget.CheckBox;
import android.widget.ImageView;

import androidx.annotation.NonNull;

import com.ldc.common.common.CommonRecyclerView;
import com.ldc.common.common.CommonRecyclerViewHolder;
import com.ldc.common.utils.TimeUtils;
import com.ldc.wandroid.R;
import com.ldc.wandroid.model.MyCollectModel;
import com.squareup.picasso.MemoryPolicy;
import com.squareup.picasso.Picasso;

import java.util.Date;

public class MyCollectAdapter extends CommonRecyclerView<MyCollectModel.DatasBean> {
    public MyCollectAdapter() {
        super(R.layout.layout_item_my_collect_item);
    }


    @Override
    protected void convert2Data(@NonNull CommonRecyclerViewHolder baseViewHolder, MyCollectModel.DatasBean dt, int position) {
        if (null == dt) {
            return;
        }
        baseViewHolder.setText(R.id.tv_title, String.format("%s", dt.getChapterName()));
        baseViewHolder.setText(R.id.tv_context, String.format("%s\n%s", dt.getTitle(), dt.getDesc()));
        baseViewHolder.setText(R.id.tv_time, String.format("%s", TimeUtils.date2String(new Date(dt.getPublishTime()), "yyyy/MM/dd HH:mm")));
        baseViewHolder.setText(R.id.tv_author, String.format("%s", dt.getAuthor()));
        //收藏的
        ((CheckBox) baseViewHolder.findViewById(R.id.ck_collect)).setChecked(true);
        // 显示图片
        if (!TextUtils.isEmpty(dt.getEnvelopePic())) {
            Picasso.get().load(dt.getEnvelopePic())
                    .resize(100, 80).memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE)

                    .placeholder(R.drawable.icon_image_helper).into((ImageView) baseViewHolder.findViewById(R.id.iv_icon_pic));
        } else {
            Picasso.get().load(R.drawable.icon_image_helper).into((ImageView) baseViewHolder.findViewById(R.id.iv_icon_pic));

        }
        //
        if (!TextUtils.isEmpty(dt.getEnvelopePic())) {
            baseViewHolder.findViewById(R.id.iv_icon_pic).setVisibility(View.VISIBLE);
            Picasso.get().load(dt.getEnvelopePic())
                    .resize(100, 100)
                    .centerCrop().memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE)

                    .placeholder(R.drawable.icon_image_helper)
                    .into((ImageView) baseViewHolder.findViewById(R.id.iv_icon_pic));
        } else {
            baseViewHolder.findViewById(R.id.iv_icon_pic).setVisibility(View.GONE);
        }
    }
}
